<?php
    class Order_m extends Model{
        function Order_m(){
            parent::Model();
            $this->load->database();    
        }
        function get_all_order($per_page,$offset){
            $this->db->select('commande.id,commande.dat,commande.montant,commande.livre, client.nom as clientnom');
            $this->db->from('commande');
            $this->db->join('client', 'commande.idclient = client.id');  
            $this->db->limit($per_page,$offset);
            $query=$this->db->get();
            return $query->result_array();
        }
         function get_order($id){
            $this->db->select('commande.*, client.nom as clientnom, method_paiement.nom as methodnom');
            $this->db->from('commande');
            $this->db->join('client', 'commande.idclient = client.id');
            $this->db->join('method_paiement', 'commande.method = method_paiement.id');   
            $this->db->where(array('commande.id'=>$id));
            $query=$this->db->get();
         return $query->row_array();  
      }
      function delete_order($id){
          $this->db->delete('detail_commande',array('idcommande'=>$id));   
           return $this->db->delete('commande',array('id'=>$id));   
      }
       function get_detail_order($id){
            $this->db->select('detail_commande.*, animaux.nom as nom, animaux.prix as prix, animaux.img as img ');
            $this->db->from('detail_commande');
            $this->db->join('animaux', 'detail_commande.idproduit = animaux.id');
            $this->db->where(array('detail_commande.idcommande'=>$id));
            $query=$this->db->get();
         return $query->result_array();  
      }
     function update_date_livraison($id){
         $dat=date('Y-m-d');
         $array=array('livre'=>$dat); 
        return $this->db->update('commande',$array,array('id'=>$id));   
     }
     
    }
?>
